package com.android.aircondition.view;


import android.content.Context;
import android.util.AttributeSet;
import android.view.animation.AlphaAnimation;
import android.view.animation.AnimationSet;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.android.aircondition.R;
import com.android.aircondition.service.GreeService;

public class ModeZhilengView extends RelativeLayout{
	private SnowFlakeImageView snowflakes0 ;
	private SnowFlakeImageView snowflakes1 ;
	private SnowFlakeImageView snowflakes2 ;
	private SnowFlakeImageView snowflakes3 ;
	private SnowFlakeImageView snowflakes4 ;
	private SnowFlakeImageView snowflakes5 ;
	private SnowFlakeImageView snowflakes6 ;
	private SnowFlakeImageView snowflakes7 ;
	private SnowFlakeImageView snowflakes8 ;
	private SnowFlakeImageView snowflakes9 ;
	private SnowFlakeImageView snowflakes10 ;
	private SnowFlakeImageView snowflakes11 ;
	
	
	private GreeService service;
	
	public ModeZhilengView(Context context) {
		super(context,null);
		initData(context);
	}

	public ModeZhilengView(Context context, AttributeSet attrs) {
		super(context, attrs);
		initData(context);
		
	}

	private void initData(Context context){
		
 		service = new GreeService(context);
 		
 		setBackgroundResource(R.drawable.frost);
 		
 		snowflakes0  = new SnowFlakeImageView(context); 
 		snowflakes1  = new SnowFlakeImageView(context); 
 		snowflakes2  = new SnowFlakeImageView(context); 
 		snowflakes3  = new SnowFlakeImageView(context); 
 		snowflakes4  = new SnowFlakeImageView(context); 
 		snowflakes5  = new SnowFlakeImageView(context); 
 		snowflakes6  = new SnowFlakeImageView(context); 
 		snowflakes7  = new SnowFlakeImageView(context); 
 		snowflakes8  = new SnowFlakeImageView(context); 
 		snowflakes9  = new SnowFlakeImageView(context); 
 		snowflakes10 = new SnowFlakeImageView(context); 
 		snowflakes11 = new SnowFlakeImageView(context); 
 		
 		LayoutParams snowflakesParam0  = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
 		LayoutParams snowflakesParam1  = new LayoutParams(60,66);
 		LayoutParams snowflakesParam2  = new LayoutParams(30,32);
 		LayoutParams snowflakesParam3  = new LayoutParams(50,56);
 		LayoutParams snowflakesParam4  = new LayoutParams(30,32);
 		LayoutParams snowflakesParam5  = new LayoutParams(30,32);
 		LayoutParams snowflakesParam6  = new LayoutParams(80,87);
 		LayoutParams snowflakesParam7  = new LayoutParams(60,66);
 		LayoutParams snowflakesParam8  = new LayoutParams(30,32);
 		LayoutParams snowflakesParam9  = new LayoutParams(50,56);
 		LayoutParams snowflakesParam10 = new LayoutParams(40,48);
 		LayoutParams snowflakesParam11 = new LayoutParams(60,66);
 		
 		snowflakesParam0.addRule(RelativeLayout.CENTER_IN_PARENT);
 		
 		snowflakesParam1.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
 		snowflakesParam1.setMargins(0, 80, 100, 0);
 		
 		snowflakesParam2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
 		snowflakesParam2.addRule(RelativeLayout.CENTER_VERTICAL);
 		snowflakesParam2.setMargins(0, 150, 150, 0);
 		
 		snowflakesParam3.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
 		snowflakesParam3.setMargins(160, 100, 0, 0);
 		
 		snowflakesParam4.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
 		snowflakesParam4.setMargins(250, 100, 0, 0);
 		
 		snowflakesParam5.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
 		snowflakesParam5.setMargins(140, 180, 0, 0);
 		
 		snowflakesParam6.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
 		snowflakesParam6.setMargins(50, 250, 0, 0);
 		
 		snowflakesParam7.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
 		snowflakesParam7.setMargins(80, 180, 0, 0);
 		
 		snowflakesParam8.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
 		snowflakesParam8.setMargins(150, 270, 0, 0);
 		
 		snowflakesParam9.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
 		snowflakesParam9.setMargins(280, 270, 0, 0);
 		
 		snowflakesParam10.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
 		snowflakesParam10.setMargins(330, 250, 0, 0);
 		
 		snowflakesParam11.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
 		snowflakesParam11.setMargins(380, 250, 0, 0);
 		
 		
 		snowflakes0.setLayoutParams(snowflakesParam0);
 		snowflakes1.setLayoutParams(snowflakesParam1);
 		snowflakes2.setLayoutParams(snowflakesParam2);
 		snowflakes3.setLayoutParams(snowflakesParam3);
 		snowflakes4.setLayoutParams(snowflakesParam4);
 		snowflakes5.setLayoutParams(snowflakesParam5);
 		snowflakes6.setLayoutParams(snowflakesParam6);
 		snowflakes7.setLayoutParams(snowflakesParam7);
 		snowflakes8.setLayoutParams(snowflakesParam8);
 		snowflakes9.setLayoutParams(snowflakesParam9);
 		snowflakes10.setLayoutParams(snowflakesParam10);
 		snowflakes11.setLayoutParams(snowflakesParam11);
 		
 		this.addView(snowflakes0);
 		this.addView(snowflakes1);
 		this.addView(snowflakes2);
 		this.addView(snowflakes3);
 		this.addView(snowflakes4);
 		this.addView(snowflakes5);
 		this.addView(snowflakes6);
 		this.addView(snowflakes7);
 		this.addView(snowflakes8);
 		this.addView(snowflakes9);
 		this.addView(snowflakes10);
 		this.addView(snowflakes11);
		
	}
	
	public void startZhireAnimation(){
		AlphaAnimation animation  = new AlphaAnimation(0.0f, 1.0f);
		AlphaAnimation animation0 = new AlphaAnimation(0.0f, 1.0f);
		AlphaAnimation animation1 = new AlphaAnimation(0.0f, 1.0f);
		AlphaAnimation animation2 = new AlphaAnimation(0.0f, 1.0f);
		AlphaAnimation animation3 = new AlphaAnimation(0.0f, 1.0f);
		AnimationSet set = new AnimationSet(true);
		set.setInterpolator(new LinearInterpolator());
		
		snowflakes0 .setAnimation(animation0);
		snowflakes1 .setAnimation(animation0);
		snowflakes2 .setAnimation(animation0);
		snowflakes3 .setAnimation(animation1);
		snowflakes4 .setAnimation(animation1);
		snowflakes5 .setAnimation(animation1);
		snowflakes6 .setAnimation(animation2);
		snowflakes7 .setAnimation(animation2);
		snowflakes8 .setAnimation(animation2);
		snowflakes9 .setAnimation(animation3);
		snowflakes10.setAnimation(animation3);
		snowflakes11.setAnimation(animation3);
		this.setAnimation(animation);
		
		animation .setDuration(1000);
		animation0.setDuration(1000);
		animation1.setDuration(1000);
		animation2.setDuration(1000);
		animation3.setDuration(1000);
		
		animation .setStartOffset(0);
		animation0.setStartOffset(1000);
		animation1.setStartOffset(2000);
		animation2.setStartOffset(3000);
		animation3.setStartOffset(4000);
		
		set.addAnimation(animation);
		set.addAnimation(animation0);
		set.addAnimation(animation1);
		set.addAnimation(animation2);
		set.addAnimation(animation3);
		
		set.start();
		
	}
	
	private class SnowFlakeImageView extends ImageView{

		public SnowFlakeImageView(Context context) {
			super(context);
			this.setBackgroundResource(R.drawable.snowflakes);
		}
		
	}
	
}
